﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;


public partial class CMS_Control_CommonInfo : System.Web.UI.UserControl
{
    Usas.BLL.Cms.cms_block_common_detail cbcd = new Usas.BLL.Cms.cms_block_common_detail();
    Usas.Model.Cms.cms_block_common_detail cbcdm = new Usas.Model.Cms.cms_block_common_detail();
    Usas.BLL.Cms.cms_block cb = new Usas.BLL.Cms.cms_block();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string id = cb.GetList("b_path='CommonInfo.ascx'").Tables[0].Rows[0]["b_id"].ToString();
            //string type = System.IO.Path.GetFileName(HttpContext.Current.Request.Path);
            string type = "Default.aspx";

            DataSet ds = cbcd.GetList("c_b_id=" + id + " and c_type='" + type + "'");

            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                Literal ul = new Literal();
                ul.Text = " <ul style=\"list-style: none; margin-left: 5px; line-height: 30px;\">";
                LitLi.Controls.Add(ul);

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    string temp_path = Server.MapPath("~/UploadFile/CommonInfo/" + ds.Tables[0].Rows[i]["c_value"].ToString());
                    if (File.Exists(temp_path))
                    {
                        string _t = Path.GetExtension(ds.Tables[0].Rows[i]["c_value"].ToString());
                        if (_t == ".gif" || _t == ".jpg" || _t == ".png")
                        {
                            Literal li = new Literal();
                            li.Text = "<li><a href='javascript:void(0)' onclick=\"var diag = new Dialog();diag.Width =850;diag.Height = 540;" +
                                "diag.MessageTitle = '';diag.Message = '';diag.Title = '" + ds.Tables[0].Rows[i]["c_des"].ToString() + "';diag.URL='../UploadFile/CommonInfo/" +
                                ds.Tables[0].Rows[i]["c_value"].ToString() + "';diag.show();return false\" class='link' style='font-size: 15px; text-decoration: none;'>" + ds.Tables[0].Rows[i]["c_des"].ToString() + "</a></li>";
                            LitLi.Controls.Add(li);
                        }
                        else if (_t == ".WAB" || _t == ".wab")
                        {
                            Literal li = new Literal();
                            li.Text = "<li>";
                            LitLi.Controls.Add(li);


                            HyperLink hy = new HyperLink();
                            hy.NavigateUrl = "../../UploadFile/CommonInfo/" + ds.Tables[0].Rows[i]["c_value"].ToString();
                            hy.Text = ds.Tables[0].Rows[i]["c_des"].ToString();
                            hy.CssClass = "link";
                            hy.Target = "_blank";
                            hy.Attributes.Add("style", "font-size: 15px; text-decoration: none;");
                            LitLi.Controls.Add(hy);

                            Literal lie = new Literal();
                            lie.Text = "</li>";
                            LitLi.Controls.Add(lie);
                        }
                        else
                        {
                            Literal li = new Literal();
                            li.Text = "<li><a href='javascript:void(0)' style='font-size: 15px; text-decoration: none;' onclick=\"window.open('../UploadFile/CommonInfo/" + ds.Tables[0].Rows[i]["c_value"].ToString() + "')\" class='link' >" + ds.Tables[0].Rows[i]["c_des"].ToString() + "</a></li>";
                            LitLi.Controls.Add(li);
                        }
                    }
                }
                Literal sul = new Literal();
                sul.Text = " </UL>";
                LitLi.Controls.Add(sul);
            }
        }
    }
}
